<template>
    <div class="login">
      <el-form>
        <el-form-item label="账号" >
          <el-input  v-model="user" ></el-input>
        </el-form-item>
        <el-form-item label="密码" >
          <el-input type="password" v-model="Pass" ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
    export default {
      name: "login",
      data() {
        return {
            user: '',
            Pass: '',
            isBtnLoading : false,
        }
      },
      methods: {
        resetForm: function () {
          let that = this;
          that.user = '';
          that.Pass = '';
        },
        submitForm: function () {
          let that = this;
          let user = this.user;
          let password = this.Pass;
          console.log(user);
          console.log(password);
          if (user == "" && password == "") {
            that.$message({
              type: 'info',
              message: '不能为空!'
            });

          } else {
          let formData = new FormData();
          formData.append('user', user);
          formData.append('password', password);
          this.axios({
            url: '/api/login',
            method: 'post',
            data: formData
          }).then(function (response) {
            console.log(response);
            if (response.status === 200) {
              that.isBtnLoading = response.data.m12confirm;
              console.log(">>>>>>", that.isBtnLoading);
              if (that.isBtnLoading === true) {
                console.log("判断正确！");
                that.$router.push({path: '/blog'});
                console.log("确认跳转！");
              } else {
                that.$message({
                  type: 'info',
                  message: '密码错误!'
                });
              }
            } else {
              alert("工厂倒闭了，你离远点~")
            }
          })
            .catch(function (error) {
              alert("你干什么？？？");
              console.log(error);
            });

        }
      }
      },
    }
</script>

<style scoped>
.login{
  width: 400px;
  margin: 20% auto;


}
</style>
